package com.itotem.android.everbridge.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ViewFlipper;

import com.itotem.android.everbridge.R;
import com.itotem.android.everbridge.utils.DimensionPixelUtil;

public class TitleView extends LinearLayout {
//	private static final String TAG = "TitleView";
	private Context mContext;
	public View titleView;
	public Button leftBackImage ;
	public RelativeLayout leftImage;
	public TextView titleText;
	public Button rightImage;
	public Button rightStopBtn;
	public Button rightRebroadBtn;
	
	public View getLeftImage() {
		return leftImage;
	}

	public void setLeftImage(View leftImage) {
		this.leftImage = (RelativeLayout)leftImage;
	}
	public View getRightImage() {
		return rightImage;
	}
	
	public void setRightImage(View rightImage) {
		this.rightImage = (Button)rightImage;
	}

	public TitleView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		mContext = context;
		initTitleView(context);
	}
	
	public void initTitleView(Context context){
		this.setOrientation(VERTICAL);
		titleView = LayoutInflater.from(context).inflate(R.layout.layout_title_top, null);
		leftImage = (RelativeLayout)titleView.findViewById(R.id.title_left_config);
		leftBackImage = (Button)titleView.findViewById(R.id.title_left_back);
		rightImage = (Button)titleView.findViewById(R.id.title_right_send);
		titleText = (TextView) titleView.findViewById(R.id.title_center_txt);
		rightStopBtn = (Button)titleView.findViewById(R.id.title_right_stop);
		rightRebroadBtn = (Button)titleView.findViewById(R.id.title_right_rebroad);
	}
	
	public void addView(View child){
		//add title
		float  height = DimensionPixelUtil.getDimensionPixelSize(1, 40, mContext);
		
//		Log.w(TAG," height : "+height);
		super.addView(titleView, LinearLayout.LayoutParams.FILL_PARENT, (int)height);
		super.addView(child);
	}
	
	public void setLeftBackButtonText(String sLeftBtton) {
		leftBackImage.setText(sLeftBtton);
	}	
	
	public void setText(String titleName) {
		titleText.setText(titleName);
	}
	
	public void setLeftBackListener(OnClickListener l){
		leftBackImage.setOnClickListener(l);
	}
	
	public void setLeftConfigListener(OnClickListener l) {
		leftImage.setOnClickListener(l);
	}
	
	public void setRightImageListener(OnClickListener l){
		rightImage.setOnClickListener(l);
//		leftImage.setClickable(false);
	}
	
	public void setRightStopImageListener(OnClickListener l) {
		rightStopBtn.setOnClickListener(l);
	}
	
	public void setRightRebroadImageListener(OnClickListener l) {
		rightRebroadBtn.setOnClickListener(l);
	}
	
	public void setRightStopImageVisible(boolean isVisible){
		if (isVisible) {
			rightStopBtn.setVisibility(View.VISIBLE);
		} else {
			rightRebroadBtn.setVisibility(View.GONE);
		}
	}
	
	public void setRightRebroadImageVisible(boolean isVisible){
		if (isVisible) {
			rightRebroadBtn.setVisibility(View.VISIBLE);
		} else {
			rightRebroadBtn.setVisibility(View.GONE);
		}
	}
	
	public void setLeftImageVisible(boolean isVisible){
		if(isVisible){
			leftImage.setVisibility(View.VISIBLE);
		}else{
			leftImage.setVisibility(View.GONE);
		}
	}
	
	public void setLeftBackImageVisible(boolean isVisible){
		if(isVisible){
			leftBackImage.setVisibility(View.VISIBLE);
		}else{
			leftBackImage.setVisibility(View.GONE);
		}
	}
	
	public void setRightImageVisible(boolean isVisible){
		if(isVisible){
			rightImage.setVisibility(View.VISIBLE);
		}else{
			rightImage.setVisibility(View.GONE);
		}
	}
	public void setTitleTextContent(CharSequence charSequence){
		titleText.setText(charSequence);
	}
}
